﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.BLL;
using Com.CMS263.Util;

namespace Com.CMS263.Web.manage.MyStyle
{
    public partial class View : System.Web.UI.Page
    {
       public int level = 0;
       public  Com.CMS263.PO.MyStyle style = null;
        MyStyleBLL bll = new MyStyleBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty("level"))
                {
                    level = int.Parse(Request["level"]);
                    style = bll.GetStyleByLevel(level);
                    if (style == null)
                    {
                        Response.Redirect("add.aspx?level="+level);
                    }
                    this.hdfId.Value = level.ToString();
                   
                    this.dvdNum.Text = style.DvdNum;
                    this.clothId.Text = style.ClothId.ToString();
                    this.winId.Text = style.WinId.ToString();
                    this.demId.Text = style.DemId.ToString();
                    this.gift.Text = style.Gift.ToString();
                    this.album.Text = style.Album;
                    this.orderNum.Text = style.Ordernum.ToString();
                    this.xtId.Text = style.XtId.ToString();
                    this.price.Text = style.Price.ToString();
                    this.desc.Text = style.Description;
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
           
            int price = 0;
            
            string dvdNum = null;
            string album = null;
            int clothid = 0;
            int demId = 0;
            int xtId = 0;
            int gift = 0;
            int winId = 0;
            string description = null;
            level = int.Parse(this.hdfId.Value);
            Com.CMS263.PO.MyStyle mystyle = bll.GetStyleByLevel(level);
    
           
            if (!string.IsNullOrEmpty(this.price.Text))
            {
                try
                {
                    price = int.Parse(this.price.Text);
                }
                catch (Exception ex)
                {

                    StringUtil.Alert("请填写正确的价格", "-1");
                }
            }
            else
            {
                StringUtil.Alert("请填写价格", "-1");
            }

           
            if (!string.IsNullOrEmpty(this.album.Text))
            {
                album = StringUtil.checkStr(this.album.Text);
            }
            else
            {
                StringUtil.Alert("请填写相册的描述", "-1");
            }

          

            if (!string.IsNullOrEmpty(this.dvdNum.Text))
            {
                dvdNum = StringUtil.checkStr(this.dvdNum.Text);
            }
            else
            {
                StringUtil.Alert("赠送dvd得描述", "-1");
            }


            if (!string.IsNullOrEmpty(this.clothId.Text))
            {
                try
                {
                    clothid = int.Parse(this.clothId.Text);
                }
                catch (Exception ex)
                {

                    StringUtil.Alert("请填写正确的编号", "-1");
                }
            }
            else
            {
                StringUtil.Alert("请填写婚纱编号", "-1");
            }


            if (!string.IsNullOrEmpty(this.demId.Text))
            {
                try
                {
                    demId = int.Parse(this.demId.Text);
                }
                catch (Exception ex)
                {

                    StringUtil.Alert("请填写正确的珠宝编号", "-1");
                }
            }
            else
            {
                StringUtil.Alert("请填写珠宝编号", "-1");
            }

            if (!string.IsNullOrEmpty(this.xtId.Text))
            {
                try
                {
                    xtId = int.Parse(this.xtId.Text);
                }
                catch (Exception ex)
                {

                    StringUtil.Alert("请填写正确的喜帖编号", "-1");
                }
            }
            else
            {
                StringUtil.Alert("请填写喜帖编号", "-1");
            }

            if (!string.IsNullOrEmpty(this.gift.Text))
            {
                try
                {
                    gift = int.Parse(this.gift.Text);
                }
                catch (Exception ex)
                {

                    StringUtil.Alert("请填写正确的礼品编号", "-1");
                }
            }
            else
            {
                StringUtil.Alert("请填写礼物编号", "-1");
            }

            if (!string.IsNullOrEmpty(this.winId.Text))
            {
                try
                {
                    winId = int.Parse(this.winId.Text);
                }
                catch (Exception ex)
                {

                    StringUtil.Alert("请填写正确的喜酒编号", "-1");
                }
            }
            else
            {
                StringUtil.Alert("请填写喜酒编号", "-1");
            }
            if (!string.IsNullOrEmpty(this.desc.Text))
            {
                description = StringUtil.checkStr(this.desc.Text);
            }
            else
            {
                StringUtil.Alert("请填写风格的描述", "-1");
            }
            
            mystyle.Price = price;
            mystyle.Title = " ";
            mystyle.WinId = winId;
            mystyle.XtId = xtId;
            mystyle.Gift = gift;
            mystyle.Album = album;
            mystyle.DvdNum = dvdNum;
            mystyle.DemId = demId;
            mystyle.ClothId = clothid;
            mystyle.Album = album;
            mystyle.Description = description;
            mystyle.Ordernum = int.Parse(this.orderNum.Text);

            if (bll.UpDate(mystyle))
            {
                StringUtil.Alert("修改成功", "View.aspx?level="+mystyle.Stylelevel);
            }
            else
            {
                StringUtil.Alert("修改失败，请重试", "-1");
            }
        }
    }
}
